package problem611;

//611.有效三角形的个数
//https://leetcode.cn/problems/valid-triangle-number/

import java.util.Arrays;

class Solution {
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int c = nums.length-1;
        int count = 0;
        while(c >= 2) {
            int left = 0, right = c-1;
            while(left < right) {
                if(nums[left] + nums[right] > nums[c]) {
                    count += (right-left);
                    right--;
                }else {
                    left++;
                }
            }
            c--;
        }
        return count;
    }
}